/********************************************************************
  A SymbolBrowser plugin for JuffEd editor.

  Copyright: 2010 Aleksander Sokoloff <asokol@mail.ru>


  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License.
  version 2 as published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*********************************************************************/


#include "katesybmolbrowserconfigpage.h"
#include "katesymbolbrowserplugin.h"
#include <kconfiggroup.h>
#include <kglobal.h>

#include <klocale.h>

#include <QGroupBox>
#include <QCheckBox>
#include <QVBoxLayout>

#include <QDebug>


/**********************************************************
 *
 **********************************************************/
KateSybmolBrowserConfigPage::KateSybmolBrowserConfigPage(QWidget *parent) :
    Kate::PluginConfigPage(parent)
{
    // Behaviour group ............................
    mGroupBehaviour = new QGroupBox(this);
    mGroupBehaviour->setTitle(i18n("Behaviour:"));

    mActivateOnSingleClickCbk = new QCheckBox(i18n("Activate on single click"), mGroupBehaviour);
    connect(mActivateOnSingleClickCbk, SIGNAL(stateChanged(int)), this, SIGNAL(changed()));

    mGroupBehaviourLayout = new QVBoxLayout(mGroupBehaviour);
    mGroupBehaviourLayout->addWidget(mActivateOnSingleClickCbk);


    // Default group ..............................
    mGroupDefault = new QGroupBox(this);
    mGroupDefault->setTitle(i18n("By default:"));

    mDetailCbk = new QCheckBox(i18n("Display functions parameters"), mGroupDefault);
    connect(mDetailCbk, SIGNAL(stateChanged(int)), this, SIGNAL(changed()));

    mSortCbk = new QCheckBox(i18n("Sort by name"), mGroupDefault);
    connect(mSortCbk, SIGNAL(stateChanged(int)), this, SIGNAL(changed()));

    mExpandCbk = new QCheckBox(i18n("Automatically expand nodes"), mGroupDefault);
    connect(mExpandCbk, SIGNAL(stateChanged(int)), this, SIGNAL(changed()));

    mGroupDefaultLayout = new QVBoxLayout(mGroupDefault);
    mGroupDefaultLayout->addWidget(mDetailCbk);
    mGroupDefaultLayout->addWidget(mSortCbk);
    mGroupDefaultLayout->addWidget(mExpandCbk);


    QVBoxLayout* layout = new QVBoxLayout(this);
    layout->addWidget(mGroupBehaviour);
    layout->addWidget(mGroupDefault);
    layout->addStretch();
    setLayout(layout);

    reset();
}


/**********************************************************
 *
 **********************************************************/
KateSybmolBrowserConfigPage::~KateSybmolBrowserConfigPage()
{
}


/**********************************************************
 *
 **********************************************************/
void KateSybmolBrowserConfigPage::apply()
{
    KConfigGroup config(KGlobal::config(), CONFIG_GROUP);

    config.writeEntry("ActivateOnSingleClick", mActivateOnSingleClickCbk->isChecked());

    config.writeEntry("Detail", mDetailCbk->isChecked());
    config.writeEntry("Sort",   mSortCbk->isChecked());
    config.writeEntry("Expand", mExpandCbk->isChecked());

    config.sync();

    emit settingsChanged();
}


/**********************************************************
 *
 **********************************************************/
void KateSybmolBrowserConfigPage::reset()
{
    KConfigGroup config(KGlobal::config(), CONFIG_GROUP);

    mActivateOnSingleClickCbk->setChecked(config.readEntry("ActivateOnSingleClick", true));

    mDetailCbk->setChecked(config.readEntry("Detail", true));
    mSortCbk->setChecked(config.readEntry("Sort", true));
    mExpandCbk->setChecked(config.readEntry("Expand", true));
}


/**********************************************************
 *
 **********************************************************/
void KateSybmolBrowserConfigPage::defaults()
{
    KConfigGroup config(KGlobal::config(), CONFIG_GROUP);

    config.revertToDefault("ActivateOnSingleClick");

    config.revertToDefault("Detail");
    config.revertToDefault("Sort");
    config.revertToDefault("Expand");
}

